/* 二次封装了 */
function ajax(){
    //创建实例
    const server = axios.create({
        baseURL: 'http://localhost:8080/api',
        //请求超时
        timeout: 20000,
    });
    server.interceptors.request.use(function (config) {
        //开启进度条
        NProgress.start();

        return config;
    }, function (error) {
        return Promise.reject(error);
    });

    server.interceptors.response.use(function (res) {
        //关闭进度条
        NProgress.done();
        if(res.data.code == 200){
            return res.data;
        }else{
            window.location.href = "./home.html"
        }
    }, function (error) {
        return Promise.reject(error);
    });
    return server
}
